package com.chcit.share.generator.service;/**
 * <Description> <br>
 *
 * @author liuyang
 * @version 1.0
 * @createDate 2019/04/23 15:32
 * @see com.chcit.share.generator.service
 */

import com.alibaba.fastjson.JSONObject;
import com.chcit.share.dbms.model.Table;
import com.chcit.share.dbms.vo.ConnParam;
import com.chcit.share.generator.model.TemplateModel;
import com.chcit.share.generator.vo.GenerateModel;
import com.chcit.share.generator.vo.GenerationEntity;

import javax.servlet.http.HttpServletResponse;
import java.io.IOException;
import java.util.List;
import java.util.Map;

/**
 *
 *@description:
 *@author: liuyang
 *@time: 2019/4/23 15:32
 *
 */
public interface GenerateService {

    /**
     * 是否可以连接
     * @param connParam
     * @return
     */
    boolean testConnection(ConnParam connParam);

    /**
     * 反向查找数据表
     * @param connParam
     * @return
     */
    List<Table> getTables(ConnParam connParam);

    /**
     * 获取代码生成数据模型
     * @param tables
     * @return
     */
    GenerateModel getGenerateModel(GenerateModel generateModel);

    /**
     * 生成代码文件
     * @param generateModel
     * @return
     * @throws IOException
     */
    JSONObject generateModels(GenerateModel generateModel) throws Exception;


    /**
     * 生成代码文件
     * @param templateString 自定义的模板
     * @param generateModel
     * @return
     * @throws Exception
     */
    String generateModels(Map<String,Object> bindKey,String templateString,GenerateModel generateModel)throws Exception;

    /**
     * 获取文件
     * @param templateList
     * @return
     */
    List<String> loadTemplateFile(List<TemplateModel> templateList);

    boolean writeThisFileList(String localPath, String encoded, List<String> fileList, List<TemplateModel> templateList, GenerationEntity ge);

    boolean downThisFileList(HttpServletResponse res, List<String> fileList, List<TemplateModel> templateList, GenerationEntity ge);

}
